package com.shiguiwu.springmybatis.designpattern.builder.scene;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @description: 填充器
 * @author: stone
 * @date: Created by 2021/8/15 23:37
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.designpattern.builder.scene
 */
public class DecorationPackageMenu implements IMenu{

    //面积
    private BigDecimal area;

    //物料清单
    private List<Matter> matters = new ArrayList<>();

    //装修类型 豪华欧式、轻奢⽥田园、现代简约
    private String grade;

    private BigDecimal price = BigDecimal.ZERO;

    public DecorationPackageMenu(double area, String grade) {
        this.area = new BigDecimal(area);
        this.grade = grade;
    }

    @Override
    public IMenu appendCeilling(Matter matter) {
        matters.add(matter);
        this.price = this.price.add(area.multiply(new BigDecimal("0.2")).multiply(matter.price()));
        return this;
    }

    @Override
    public IMenu appendCoat(Matter matter) {
        matters.add(matter);
        this.price = this.price.add(area.multiply(new BigDecimal("0.4")).multiply(matter.price()));
        return this;
    }

    @Override
    public IMenu appendFloor(Matter matter) {
        matters.add(matter);
        this.price = this.price.add(area.multiply(matter.price()));
        return this;
    }

    @Override
    public IMenu appendTile(Matter matter) {
        matters.add(matter);
        this.price = this.price.add(area.multiply(matter.price()));
        return this;
    }

    @Override
    public String getDetail() {

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("-------------------------------------\r\n")
                .append("装修清单\r\n").append("套餐等级：").append(grade).append("\r\n").append("价格套餐：").append(price.setScale(2, BigDecimal.ROUND_HALF_UP)).append("\r\n").append("房屋面积：").append(area.doubleValue()).append("\r\n")
                .append("材料清单： \r\n");

        matters.forEach(matter -> stringBuilder.append(matter.scene()).append("：").append(matter.brand()).append(
                "、").append(matter.model()).append("、平米价格：").append(matter.price()).append(" 元。\n"));
        return stringBuilder.toString();
    }
}
